package com.itheima_2;

public class MyTread extends Thread {
    private static int ticketCount=100;
    private static Object object=new Object();
    @Override
    public void run() {
        while (true){
            synchronized (object) {
                if (ticketCount <= 0) {
                    break;
                } else {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    ticketCount--;
                    System.out.println(Thread.currentThread().getName() + "在卖票还剩下" + ticketCount + "张票");
                }   }
        }
    }
}
